package com.jp.springboot.properties;

import com.jp.springboot.properties.po.ComplicatedProperty;
import com.jp.springboot.properties.po.YMLComplicatedProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/properties")
public class PropertiesController {
    @Autowired
    private WebConfig webConfig;

    @Autowired
    private Environment environment;

    @Autowired
    private ComplicatedProperty complicatedProperty;

    @Autowired
    private YMLComplicatedProperty ymlComplicatedProperty;

    //http://localhost:8080/properties/configurationProperties
    @GetMapping("configurationProperties")
    public String getPropertiesFromConfigurationProperties(){
        return webConfig.getName();
    }

    //http://localhost:8080/properties/value
    @GetMapping("value")
    public String getPropertiesFromValue(){
        return webConfig.getDatabaseURL();
    }

    //http://localhost:8080/properties/environment
    @GetMapping("environment")
    public String getPropertiesFromEnv(){
        return environment.getProperty("env.server.port");
    }

    //http://localhost:8080/properties/listener
    @GetMapping("listener")
    public String getPropertiesFromListener(){
        return PropertiesListenerConfig.getProperty("listener.port");
    }

    //http://localhost:8080/properties/complicated
    @GetMapping("complicated")
    public String getPropertiesFromComplicatedData(){
        System.out.println(complicatedProperty);
        System.out.println(ymlComplicatedProperty);
        return PropertiesListenerConfig.getProperty("listener.port");
    }

}
